﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Arthus.Preduzeca
{
    public partial class preduzecaForma : Form
    {
        private int idPreduzeca;
        public preduzecaForma()
        {
            InitializeComponent();
        }

        Preduzece preduzeceObjekat = null;

        private void preduzecaForma_Load(object sender, EventArgs e)
        {
            preduzeceObjekat = new Preduzece();
            preduzeceObjekat.PopuniListBox(listBoxPreduzeca);
            preduzeceObjekat.PopuniKontroleNaOsnovuIdPreduzeca(idPreduzeca, textBoxOznaka, textBoxNaziv, textBoxNaziv2, textBoxAdresa, textBoxPostanskiBroj,
                textBoxMesto, textBoxTelefon, textBoxFax, textBoxMaticniBroj, textBoxPIB, textBoxPDV, textBoxSifraDelatnosti, checkBoxObveznikPDV, textBoxWWW,
                textBoxEmail, textBoxMIR, textBoxMPD, textBoxMC1, textBoxMC2, textBoxNPO, textBoxISP, textBoxKMA, textBoxKMB, textBoxIMG);
            listBoxPreduzeca.SelectedIndex = 0;
        }

        private void preduzecaForma_Activated(object sender, EventArgs e)
        {
            preduzeceObjekat = new Preduzece();
            preduzeceObjekat.PopuniListBox(listBoxPreduzeca);
            preduzeceObjekat.PopuniKontroleNaOsnovuIdPreduzeca(idPreduzeca, textBoxOznaka, textBoxNaziv, textBoxNaziv2, textBoxAdresa, textBoxPostanskiBroj,
                textBoxMesto, textBoxTelefon, textBoxFax, textBoxMaticniBroj, textBoxPIB, textBoxPDV, textBoxSifraDelatnosti, checkBoxObveznikPDV, textBoxWWW,
                textBoxEmail, textBoxMIR, textBoxMPD, textBoxMC1, textBoxMC2, textBoxNPO, textBoxISP, textBoxKMA, textBoxKMB, textBoxIMG);
            idPreduzeca = Convert.ToInt32(listBoxPreduzeca.SelectedItem.ToString().Split('.')[0]);
        }

        private void buttonZatvori_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void TABKaoENTER(KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                e.SuppressKeyPress = true;
                SelectNextControl(ActiveControl, true, true, true, true);
            }
        }
        private void textBoxOznaka_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxNaziv_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxNaziv2_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxAdresa_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxPostanskiBroj_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxMesto_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxTelefon_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxFax_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxMaticniBroj_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxPIB_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxPDV_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxSifraDelatnosti_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void checkBoxObveznikPDV_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxWWW_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxEmail_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxMIR_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxMPD_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxMC1_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxMC2_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxNPO_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxISP_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxKMA_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxKMB_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxIMG_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }

        private void VratiSveNaPocetak()
        {
            textBoxOznaka.Text = "";
            textBoxNaziv.Text = "";
            textBoxNaziv2.Text = "";
            textBoxAdresa.Text = "";
            textBoxPostanskiBroj.Text = "";
            textBoxMesto.Text = "";
            textBoxTelefon.Text = "";
            textBoxFax.Text = "";
            textBoxMaticniBroj.Text = "";
            textBoxPIB.Text = "";
            textBoxPDV.Text = "";
            textBoxSifraDelatnosti.Text = "";
            checkBoxObveznikPDV.Checked = false;
            textBoxWWW.Text = "";
            textBoxEmail.Text = "";
            textBoxMIR.Text = "";
            textBoxMPD.Text = "";
            textBoxMC1.Text = "";
            textBoxMC2.Text = "";
            textBoxNPO.Text = "";
            textBoxISP.Text = "";
            textBoxKMA.Text = "";
            textBoxKMB.Text = "";
            textBoxIMG.Text = "";
        }

        private void buttonDodaj_Click(object sender, EventArgs e)
        {
            preduzeceObjekat = new Preduzece();
            preduzeceObjekat.DodajPreduzece(textBoxOznaka, textBoxNaziv, textBoxNaziv2, textBoxAdresa, textBoxPostanskiBroj,
                textBoxMesto, textBoxTelefon, textBoxFax, textBoxMaticniBroj, textBoxPIB, textBoxPDV, textBoxSifraDelatnosti, checkBoxObveznikPDV, textBoxWWW,
                textBoxEmail, textBoxMIR, textBoxMPD, textBoxMC1, textBoxMC2, textBoxNPO, textBoxISP, textBoxKMA, textBoxKMB, textBoxIMG);
            VratiSveNaPocetak();
            textBoxOznaka.Focus();
        }

        private void listBoxPreduzeca_SelectedIndexChanged(object sender, EventArgs e)
        {
            idPreduzeca = Convert.ToInt32(listBoxPreduzeca.SelectedItem.ToString().Split('.')[0]);
            preduzeceObjekat = new Preduzece();
            preduzeceObjekat.PopuniKontroleNaOsnovuIdPreduzeca(idPreduzeca, textBoxOznaka, textBoxNaziv, textBoxNaziv2, textBoxAdresa, textBoxPostanskiBroj,
                textBoxMesto, textBoxTelefon, textBoxFax, textBoxMaticniBroj, textBoxPIB, textBoxPDV, textBoxSifraDelatnosti, checkBoxObveznikPDV, textBoxWWW,
                textBoxEmail, textBoxMIR, textBoxMPD, textBoxMC1, textBoxMC2, textBoxNPO, textBoxISP, textBoxKMA, textBoxKMB, textBoxIMG);
        }

        private void buttonIzmeni_Click(object sender, EventArgs e)
        {
            preduzeceObjekat = new Preduzece();
            preduzeceObjekat.IzmeniPreduzece(idPreduzeca, textBoxOznaka, textBoxNaziv, textBoxNaziv2, textBoxAdresa, textBoxPostanskiBroj,
                textBoxMesto, textBoxTelefon, textBoxFax, textBoxMaticniBroj, textBoxPIB, textBoxPDV, textBoxSifraDelatnosti, checkBoxObveznikPDV, textBoxWWW,
                textBoxEmail, textBoxMIR, textBoxMPD, textBoxMC1, textBoxMC2, textBoxNPO, textBoxISP, textBoxKMA, textBoxKMB, textBoxIMG);
        }

        private void buttonObrisi_Click(object sender, EventArgs e)
        {
            preduzeceObjekat = new Preduzece();
            preduzeceObjekat.ObrisiPreduzece(idPreduzeca);
        }
    }
}
